%
% This script demonstrates how you can use glade_xml_get_widget(),
% glade_xml_get_widget_prefix(), and glade_get_widget_name() to
% manipulate widgets created by glade_xml_new().
%

import("gtk");
import("glade");

define list_widgets_by_name(xml, str) {
   variable wdg_array = glade_xml_get_widget_prefix(xml,str);
   variable wdg;

   if (wdg_array == NULL) {
      vmessage("No widgets matching prefix \"%s\"",str);
      return;
   }

   if (str == NULL)
      message("All widgets:");
   else
      vmessage("Widgets matching prefix \"%s\":",str);

   foreach (wdg_array) {
      wdg = ();
      vmessage("  %s",glade_get_widget_name(wdg));
   }
}

variable xml = glade_xml_new("howdy.glade",,);

variable win = glade_xml_get_widget(xml,"window1");
() = g_signal_connect(win,"destroy",&gtk_main_quit);

variable button = glade_xml_get_widget(xml,"button1");
() = g_signal_connect_swapped(button,"clicked",&gtk_widget_destroy,win);

list_widgets_by_name(xml,);
list_widgets_by_name(xml,"");
list_widgets_by_name(xml,"win");
list_widgets_by_name(xml,"winy");

gtk_main();

